package com.fingard.dsp.bank.directbank.citic05.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;

public class OpenBankSdkConfiguration {
    private String publicUrl;
    private int connectionTimeout = -1;
    private String openVer;
    private String openMerCode;
    private String openMerName;
    private String openBusiType;
    private String transferEncode;
    private static com.citic.openbank.configuration.OpenBankSdkConfiguration configuration;

    public OpenBankSdkConfiguration() {
    }

    public String getOpenVer() {
        return this.openVer;
    }

    public void setOpenVer(String openVer) {
        this.openVer = openVer;
    }

    public String getOpenMerCode() {
        return this.openMerCode;
    }

    public void setOpenMerCode(String openMerCode) {
        this.openMerCode = openMerCode;
    }

    public String getOpenMerName() {
        return this.openMerName;
    }

    public void setOpenMerName(String openMerName) {
        this.openMerName = openMerName;
    }

    public String getOpenBusiType() {
        return this.openBusiType;
    }

    public void setOpenBusiType(String openBusiType) {
        this.openBusiType = openBusiType;
    }

    public int getConnectionTimeout() {
        return this.connectionTimeout;
    }

    public void setConnectionTimeout(int connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    public String getPublicUrl() {
        return this.publicUrl;
    }

    public void setPublicUrl(String publicUrl) {
        this.publicUrl = publicUrl;
    }

    public static com.citic.openbank.configuration.OpenBankSdkConfiguration getConfigurationFromFile() {
        if (configuration == null) {
            configuration = new com.citic.openbank.configuration.OpenBankSdkConfiguration();
            URL file = com.citic.openbank.configuration.OpenBankSdkConfiguration.class.getClassLoader().getResource("citic/conf/config.properties");
            if (file == null) {
                throw new RuntimeException("未能加载配置文件, 请检查配置文件路径是否在 classpath 中");
            } else {
                String path = file.getPath();

                try {
                    InputStream inputStream = new FileInputStream(path);
                    Properties props = new Properties();
                    props.load(new InputStreamReader(inputStream, "utf-8"));
                    configuration.setPublicUrl(props.getProperty("public_url"));
                    configuration.setConnectionTimeout(Integer.valueOf(props.getProperty("connection_timeout")));
                    configuration.setTransferEncode(props.getProperty("transfer_encode"));
                    configuration.setOpenVer(props.getProperty("open_ver"));
                    configuration.setOpenBusiType(props.getProperty("open_busi_type"));
                    configuration.setOpenMerCode(props.getProperty("open_mer_code"));
                    configuration.setOpenMerName(props.getProperty("open_mer_name"));
                    if (configuration.getOpenBusiType() != null && !"".equals(configuration.getOpenBusiType())) {
                        if (configuration.getOpenVer() != null && !"".equals(configuration.getOpenVer())) {
                            if (configuration.getOpenMerCode() != null && !"".equals(configuration.getOpenMerCode())) {
                                if (configuration.getOpenMerName() != null && !"".equals(configuration.getOpenMerName())) {
                                    if (configuration.getPublicUrl() != null && !"".equals(configuration.getPublicUrl())) {
                                        if (configuration.getTransferEncode() != null && !"".equals(configuration.getTransferEncode())) {
                                            if (configuration.getConnectionTimeout() == -1) {
                                                throw new IllegalArgumentException("未设置 open_mer_name 变量");
                                            } else {
                                                return configuration;
                                            }
                                        } else {
                                            throw new IllegalArgumentException("未设置 transfer_encode 变量");
                                        }
                                    } else {
                                        throw new IllegalArgumentException("未设置 public_url 变量");
                                    }
                                } else {
                                    throw new IllegalArgumentException("未设置 open_mer_name 变量");
                                }
                            } else {
                                throw new IllegalArgumentException("未设置 open_mer_code 变量");
                            }
                        } else {
                            throw new IllegalArgumentException("未设置 open_ver 变量");
                        }
                    } else {
                        throw new IllegalArgumentException("未设置 open_busi_type 变量");
                    }
                } catch (FileNotFoundException var4) {
                    var4.printStackTrace();
                    throw new RuntimeException(var4);
                } catch (IOException var5) {
                    var5.printStackTrace();
                    throw new RuntimeException(var5);
                }
            }
        } else {
            return configuration;
        }
    }

    public String getTransferEncode() {
        return this.transferEncode;
    }

    public void setTransferEncode(String transferEncode) {
        this.transferEncode = transferEncode;
    }
}
